<template>
  <el-dialog width="800px" title="编辑" :close-on-click-modal="false"  :visible.sync="visible">
    <el-form  :inline="true" class="demo-form-inline editorder" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
      <el-form-item label="订单编号">
        <div class="el-input">{{dataForm.orderSn}}</div>
      </el-form-item>
      <el-form-item label="添加时间">
        <el-date-picker
          v-model="dataForm.addTimeStr"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="会员码">
         <div class="el-input">{{dataForm.specialId}}</div>
      </el-form-item>
      <el-form-item label="快递单号">
        <el-input v-model="dataForm.outTrackingNumber" placeholder="快递单号"></el-input>
      </el-form-item>
      <el-form-item label="重量/kg">
        <el-input v-model="dataForm.weight" placeholder="重量"></el-input>
      </el-form-item>
      <el-form-item label="物流渠道">
        <el-select clearable filterable  v-model="dataForm.shippingId" placeholder="物流渠道">
          <el-option
            v-for="item in shipping_names"
            :key="item.shippingId"
            :label="item.shippingName"
            :value="item.shippingId">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="收件人">
        <el-input v-model="dataForm.name" placeholder="收件人"></el-input>
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input v-model="dataForm.mobile" placeholder="联系电话"></el-input>
      </el-form-item>
      <el-form-item label="邮编">
        <el-input v-model="dataForm.zipcode" placeholder="邮编"></el-input>
      </el-form-item>
      <el-form-item label="收货地址" >
        <el-input v-model="dataForm.country" placeholder="国家"></el-input>
        <el-input v-model="dataForm.province" placeholder="州/省"></el-input>
        <el-input v-model="dataForm.city" placeholder="城市"></el-input>

      </el-form-item>
      <el-form-item label="详细地址" class="address" style="width: 100%" >
        <el-input v-model="dataForm.address" placeholder="详细地址"></el-input>
      </el-form-item>
      <el-form-item label="快递状态">
        <el-radio-group v-model="dataForm.shippingStatus">
          <el-radio :label="0">等待发货</el-radio>
          <el-radio :label="1">在途</el-radio>
          <el-radio :label="2">揽件</el-radio>
          <el-radio :label="3">疑难</el-radio>
          <el-radio :label="4">签收</el-radio>
          <el-radio :label="5">退签</el-radio>
          <el-radio :label="6">派件</el-radio>
          <el-radio :label="7">退回</el-radio>
          <el-radio :label="8">暂扣</el-radio>
        </el-radio-group>
      </el-form-item>



    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        shipping_names:[],
        visible: false,
        dataForm: {
          orderId: 0,
          addTimeStr:'',
          addTime:'',
          name:'',
          outTrackingNumber:'',
          weight:'',
          shippingId:0,
          shippingName:'',
          name:'',
          mobile:'',
          zipcode:'',
          country:'',
          province:'',
          city:'',
          address:'',
          shippingStatus:0,
        },
        dataRule: {
          payfee: [
            { required: true, message: '实际支付金额不能为空', trigger: 'blur' }
          ]

        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.orderId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderId) {
            this.$http({
              url: this.$http.adornUrl(`/order/v9order/orderinfo/${this.dataForm.orderId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orderSn = data.v9Order.orderSn
                this.dataForm.specialId = data.v9Order.specialId
                this.dataForm.name = data.v9Order.name
                this.dataForm.country = data.v9Order.country
                this.dataForm.mobile = data.v9Order.mobile
                this.dataForm.city = data.v9Order.city
                this.dataForm.province = data.v9Order.province
                this.dataForm.zipcode = data.v9Order.zipcode
                this.dataForm.address = data.v9Order.address
                this.dataForm.addTimeStr = data.v9Order.addTimeStr
                this.dataForm.weight = data.v9Order.weight
                this.dataForm.shippingId = data.v9Order.shippingId
                this.dataForm.uid=data.v9Order.uid
                this.dataForm.outTrackingNumber=data.v9Order.outTrackingNumber
                this.dataForm.shippingStatus=data.v9Order.shippingStatus
                this.shipping_names=data.shipping
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            let t=new Date(this.dataForm.addTimeStr).getTime();
            this.dataForm.addTime=parseInt(t/1000)
            this.$http({
              url: this.$http.adornUrl(`/order/v9order/update`),
              method: 'post',
              data: this.$http.adornData(this.dataForm)
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss">
  .editorder .el-input{
    width: 200px;
  }
  .address .el-input{
    width: 400px;
  }
  .editorder .el-radio{
    margin-right: 8px;
    margin-left: 0;
  }

</style>
